import org.junit.jupiter.api.Test;

import java.util.Arrays;

public class _04_寻找两个正序数组的中位数 {

    @Test
    void test(){
        int[] arr1={0,0};
        int[] arr2={0,0};
        System.out.println(findMedianSortedArrays(arr1, arr2));
    }

    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int length = nums1.length+nums2.length;
        int[] arr=new int[length];
        for (int i = 0; i < nums1.length; i++) {
            arr[i]=nums1[i];
        }
        for (int i = 0; i < nums2.length; i++) {
            arr[nums1.length+i]=nums2[i];
        }
        Arrays.sort(arr);
        if (arr.length%2==0){
            int mid=arr.length/2;
            int sum=arr[mid-1]+arr[mid];
            if (sum==0){
                return 0;
            }else {
                double midNum=(sum)/2.0;
                return midNum;
            }

        }else {
            int mid=arr.length/2;
            double midNum=(arr[mid]);
            return midNum;
        }
    }
}
